package com.kaishengit.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kaishengit.dao.UserDao;
import com.kaishengit.entity.User;

public class AjaxServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String name = request.getParameter("username");
		System.out.println(name);
		if (name == null || "".equals(name)) {
			response.setContentType("text/html");
			PrintWriter out = response.getWriter();
			out.print("isNull");
			out.flush();
			out.close();
		} else {
			UserDao dao = new UserDao();
			User user = dao.findByUser(name);

			response.setContentType("text/html");
			PrintWriter out = response.getWriter();
			if (user == null) {

				out.print("error");
			} else {
				out.print("isOK");
			}
			out.flush();
			out.close();
		}
	}
}
